package com.dbz.controller;

import com.dbz.entity.Product;
import com.dbz.entity.ProductJin;
import com.dbz.entity.Warehouse;
import com.dbz.service.ProductService;
import com.dbz.service.WarehouseService;
import com.dbz.service.WarehousingService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/warehouse/")
public class WarehouseController {
    @Resource
    private WarehouseService warehouseService;
@Resource
private WarehousingService warehousingService;
    @Resource
    private ProductService productService;
    /**
     * 查询所有仓库
     * @return
     */
    @RequestMapping("warehouseList")
     public List<Warehouse> warehouseList(){
         return  warehouseService.selectWarehouse();
     }

     @RequestMapping("insertProduct")
    public int insertProduct(ProductJin productJin){
         warehousingService.updatewarestate(productJin.getWid());
        List<Product> products =productService.selectProductGetAll();
         for (Product product: products
              ) {
             if (productJin.getWname().equals(product.getProname())
                 &&productJin.getProguige().equals(product.getProguige())
                 &&productJin.getCangku().equals(product.getWareid())
                     &&productJin.getSupplierid().equals(product.getProsupplier())
             ){
                Integer proNumer=productJin.getNumber()+product.getPronumber();
                 productService.updateProductNumber(
                         productJin.getWname(),
                         proNumer,
                         productJin.getProguige(),
                         productJin.getCangku(),
                         productJin.getSupplierid());
                 return 1;
             }


         }
        productService.insertProduct(productJin);
        return 1;
     }
}
